//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "TabulatedGaussLegendre.h"
using namespace Cephei::QL::Math::Integrals;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (Microsoft::FSharp::Core::FSharpOption<UInt64>^ n) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phTabulatedGaussLegendre = NULL;
#endif
        QuantLib::Size _n = 
            (Microsoft::FSharp::Core::FSharpOption<UInt64>::IsSome::get (n) ? (QuantLib::Size)ValueHelper::Convert (n->Value) : 20); //4
        _ppTabulatedGaussLegendre = new boost::shared_ptr<QuantLib::TabulatedGaussLegendre> (new QuantLib::TabulatedGaussLegendre ( _n ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (boost::shared_ptr<QuantLib::TabulatedGaussLegendre>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phTabulatedGaussLegendre = NULL;
#endif
	_ppTabulatedGaussLegendre = &childNative;
    
}
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (QuantLib::TabulatedGaussLegendre& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phTabulatedGaussLegendre = NULL;
#endif
	_ppTabulatedGaussLegendre = new boost::shared_ptr<QuantLib::TabulatedGaussLegendre> (&childNative);
    
    _TabulatedGaussLegendreOwner = owner;
    
}

Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (CTabulatedGaussLegendre^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phTabulatedGaussLegendre = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppTabulatedGaussLegendre = new boost::shared_ptr<QuantLib::TabulatedGaussLegendre> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phTabulatedGaussLegendre = NULL;
#endif
	if (!t->IsSubclassOf(CTabulatedGaussLegendre::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (QuantLib::Handle<QuantLib::TabulatedGaussLegendre>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phTabulatedGaussLegendre = &childNative;
	_ppTabulatedGaussLegendre = &static_cast<boost::shared_ptr<QuantLib::TabulatedGaussLegendre>>(childNative.currentLink());
    
    _TabulatedGaussLegendreOwner = owner;
}
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (QuantLib::Handle<QuantLib::TabulatedGaussLegendre> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phTabulatedGaussLegendre = &childNative;
	_ppTabulatedGaussLegendre = &static_cast<boost::shared_ptr<QuantLib::TabulatedGaussLegendre>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::CTabulatedGaussLegendre (QuantLib::TabulatedGaussLegendre childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phTabulatedGaussLegendre = NULL;
#endif
	_ppTabulatedGaussLegendre = new boost::shared_ptr<QuantLib::TabulatedGaussLegendre> (new QuantLib::TabulatedGaussLegendre (childNative));
    
}
#endif

Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::~CTabulatedGaussLegendre ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppTabulatedGaussLegendre != NULL)
    {
	    delete _ppTabulatedGaussLegendre;
        _ppTabulatedGaussLegendre = NULL;
    }
}
Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::!CTabulatedGaussLegendre ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppTabulatedGaussLegendre != NULL)
    {
	    delete _ppTabulatedGaussLegendre;
    }
}
QuantLib::TabulatedGaussLegendre& Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::GetReference ()
{
    if (_ppTabulatedGaussLegendre == NULL) throw gcnew NativeNullException ();
	return **_ppTabulatedGaussLegendre;
}
boost::shared_ptr<QuantLib::TabulatedGaussLegendre>& Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::GetShared ()
{
    if (_ppTabulatedGaussLegendre == NULL) throw gcnew NativeNullException ();
	return *_ppTabulatedGaussLegendre;
}
QuantLib::TabulatedGaussLegendre* Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::GetPointer ()
{
    if (_ppTabulatedGaussLegendre == NULL) throw gcnew NativeNullException ();
	return &**_ppTabulatedGaussLegendre;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::TabulatedGaussLegendre>& Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::GetHandle ()
{
	if (_phTabulatedGaussLegendre == NULL)
	{
		_phTabulatedGaussLegendre = new Handle<QuantLib::TabulatedGaussLegendre> (*_ppTabulatedGaussLegendre);
	}
	return *_phTabulatedGaussLegendre;
}
#endif
bool Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::HasNative () 
{
	return (_ppTabulatedGaussLegendre != NULL);
}

UInt64 Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::Order ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppTabulatedGaussLegendre)->order ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::ITabulatedGaussLegendre^ Cephei::QL::Math::Integrals::CTabulatedGaussLegendre::Order (UInt64 order)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Size _order = (QuantLib::Size)ValueHelper::Convert (order);
    	(*_ppTabulatedGaussLegendre)->order ( _order );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::ITabulatedGaussLegendre^ Cephei::QL::Math::Integrals::CTabulatedGaussLegendre_Factory::Create (Microsoft::FSharp::Core::FSharpOption<UInt64>^ n)
{
    return gcnew CTabulatedGaussLegendre ( n);
}
